home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / INTERRUP.SWG / 0009_Trapping Int21.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-17  |  3KB  |  77 lines

  1. ===========================================================================
  2.  BBS: Canada Remote Systems
  3. Date: 07-15-93 (18:15)             Number: 26295
  4. From: CHRIS PRIEDE                 Refer#: 26227
  5.   To: PIERRE DARMON                 Recvd: NO  
  6. Subj: DOS interrupt handler          Conf: (552) R-TP
  7. ---------------------------------------------------------------------------
  8. PD>What additional steps need to be taken for $21? I even tried to remove
  9. PD>the clicking part, which boils down to installing a new handler that just
  10. PD>calls the old one. Still no go. What's wrong?
  11.  
  12. PD>My ultimate goal is to trap file opens (function 3Dh), check the SHAREing
  13. PD>mode used (in AL), modify it if necessary, and execute the old handler.
  14. PD>Doesn't sound like a very complicated thing to do but ... I am stuck.
  15.  
  16.     Your handler is changing some registers or suffering from some
  17. registers being changed by INT 21. DOS EXEC service trashes everything,
  18. including SS:SP, for example. In my opinion, one can't write a stable
  19. INT 21 handler in Pascal or any other HLL. HLL interrupt handlers are
  20. usable to certain extent, but this is too low level.
  21.  
  22.     It can be done in BASM, though. We will declare interrupt handler as
  23. simple procedure with no arguments to avoid entry/exit code TP generates
  24. for interrupt handlers. Our handler will force all files to be opened in
  25. Deny Write mode (modify for your needs).
  26.  
  27.  
  28. const
  29.   shCompatibility = $00;
  30.   shDenyAll       = $10;
  31.   shDenyWrite     = $20;
  32.   shDenyRead      = $30;
  33.   shDenyNone      = $40;
  34.  
  35. procedure NewInt21; assembler;
  36. asm
  37.   cmp   ah, 3Dh         {open file?}
  38.   je    @CheckModeAL
  39.   cmp   ah, 6Ch         {DOS 4.0+ extended open?}
  40.   je    @CheckModeBL    {extended takes mode in BX}
  41.   jmp   @Chain
  42.  
  43. @CheckModeAL:
  44.   and   al, 10001111b     {clear sharing mode bits}
  45.   or    al, shDenyWrite   {set to our mode}
  46.   jmp   @Chain
  47.  
  48. @CheckModeBL:
  49.   and   bl, 10001111b
  50.   or    bl, shDenyWrite
  51.   jmp   @Chain
  52.  
  53. @I21:
  54.   DD      0       {temp. var. for old vector -- must be in code seg.}
  55.  
  56. @Chain:
  57.   push  ds
  58.   push  ax
  59.   mov   ax, SEG @Data
  60.   mov   ds, ax
  61.   mov   ax, WORD PTR OldInt21
  62.   mov   WORD PTR cs:[offset @I21], ax
  63.   mov   ax, WORD PTR OldInt21 +2
  64.   mov   WORD PTR cs:[offset @I21 +2], ax
  65.   pop   ax
  66.   pop   ds
  67.   jmp   DWORD PTR cs:[offset @I21]
  68. end;
  69.  
  70.  
  71.     To try this save old vector in a global variable named OldInt21 and
  72. install this handler as usual. It also traps function 6Ch, DOS 4.0+
  73. extended open/create. Very few programs use it, but why not...
  74. ---
  75.  * Faster-Than-Light (FTL) ■ Atlanta, GA ■ 404-292-8761/299-3930
  76.  * PostLink(tm) v1.06  FTL (#93) : RelayNet (tm)
  77.